// pages/MainPage/ComPage/ComPage.js
var myDate = new Date() 
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:"",
    ind:{},
    listRe:[]
  },

  formSubmit(e){
    console.log(e.detail.value)
    var info = {}
    var data = {}
    var that = this
    var id = this.data.id
    var reply = e.detail.value.reply
    var time = myDate.toLocaleDateString();
    info = wx.getStorageSync('userInfo')
    if(!info){
      wx.getUserProfile({
        desc: '该信息仅用于展示在个人中心',
        lang: 'zh-cn',
        success: (res) => {
            this.setData({
                hasUserInfo:true,
                userInfo:res.userInfo
            });
            wx.setStorage({
                key:"userInfo",
                data:res.userInfo
            });
        },
      })
    }
    data = {
      'id': id,
      'reply-er': app.globalData.userInfo.nickName,
      'reply': reply,
      'time': time
    }
    console.log(data)
    wx.request({
      url: app.globalData.url+'/postrep',
      method: 'POST',
      header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      data:data,
      success:function(el){
        console.log('成功');
        console.log(el);
        wx.showToast({
          title: '发送成功！',
        });
        setTimeout(()=>
        {
          console.log("");
          wx.request({
            url: app.globalData.url+'/submitc/'+that.data.id,
            method:"GET",
            success(result){
              console.log(result)
            }
          })
        }, 1000)
        setTimeout(()=>
        {
          wx.navigateBack()
        },1000)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    that.setData({
      id:options.id
    })
    console.log(options.id)
    console.log(that.data.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that = this
    wx.request({
      url: app.globalData.url+'/getspe/'+that.data.id,
      method:'GET',
      success(res){
        console.log(res);
        that.setData({
          ind:res.data
        })
      }
    })
    setTimeout(()=>
    {
      wx.request({
        url: app.globalData.url+'/getspere/'+that.data.id,
        method:'GET',
        success(res){
          console.log(res);
          that.setData({
            listRe:res.data
          })
        }
      })
    }, 100)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})